<?php

use yii\widgets\ActiveForm;
use common\helpers\Url;
use kartik\select2\Select2;

$form = ActiveForm::begin([
    'id' => $model->formName(),
    'enableAjaxValidation' => true,
    'validationUrl' => Url::to(['create', 'id' => $model['id']]),
    'fieldConfig' => [
        'template' => "<div class='col-sm-2 text-right'>{label}</div><div class='col-sm-10'>{input}\n{hint}\n{error}</div>",
    ]
]);
?>

    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title">基本信息</h4>
    </div>
    <div class="modal-body">
        <?= $form->field($model, 'begin_date')->widget(kartik\date\DatePicker::class, [
            'language' => 'zh-CN',
            'layout'=>'{picker}{input}',
            'pluginOptions' => [
                'format' => 'yyyy-mm-dd',
                'todayHighlight' => true, // 今日高亮
                'autoclose' => true, // 选择后自动关闭
                'todayBtn' => true, // 今日按钮显示
            ],
            'options'=>[
                'class' => 'form-control no_bor',
            ]
        ]) ?>
        <?= $form->field($model, 'end_date')->widget(kartik\date\DatePicker::class, [
            'language' => 'zh-CN',
            'layout'=>'{picker}{input}',
            'pluginOptions' => [
                'format' => 'yyyy-mm-dd',
                'todayHighlight' => true, // 今日高亮
                'autoclose' => true, // 选择后自动关闭
                'todayBtn' => true, // 今日按钮显示
            ],
            'options'=>[
                'class' => 'form-control no_bor',
            ]
        ]) ?>
        <?= $form->field($model, 'cate_id')->radioList(\addons\Calendar\common\enums\CalendarTypeEnum::getMap()) ?>
        <div id="attend" class="<?php if ($model->cate_id != 1){ echo 'hidden'; } ?>">
        <?= $form->field($model, 'attend')->widget(\kartik\select2\Select2::class, [
            'data' => $data,
            'options' => ['placeholder' => '用户','multiple'=>true],
            'pluginOptions' => [
                'allowClear' => true
            ],
        ]);?>
        </div>
        <?= $form->field($model, 'address')->textInput() ?>
        <?= $form->field($model, 'content')->textarea() ?>
        <?= $form->field($model, 'remind')->radioList(\addons\Flow\common\enums\RemindTypeEnum::getMap()) ?>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
        <button class="btn btn-primary" type="submit">保存</button>
    </div>
<?php ActiveForm::end(); ?>

<script>
    $("input[name='Calendar[cate_id]']").click(function () {
        var val = $(this).val();

        if (val == '1') {
            $('#attend').removeClass('hidden');
        } else {
            $('#attend').addClass('hidden');
        }

    });

</script>
